//
//  HeadViewController.m
//  SimpleTimeDemo
//
//  Created by lanou3g on 15/11/12.
//  Copyright © 2015年 王丽珍. All rights reserved.
//

#import "HeadViewController.h"
#import "UIImageView+WebCache.h"
#import "UMSocial.h"
#import "LeftViewController.h"
@interface HeadViewController ()<UMSocialUIDelegate>

- (IBAction)backButton:(UIButton *)sender;

@property (strong, nonatomic) IBOutlet UIImageView *nameImage;
@property (strong, nonatomic) IBOutlet UILabel *nameLabel;

- (IBAction)shareButton:(UIButton *)sender;


- (IBAction)exitButton:(UIButton *)sender;


@end

@implementation HeadViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 取出存在本地的数据
    NSString *documentStr = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
    NSString *path = [documentStr stringByAppendingString:@"/UserInformation.txt"];
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    _nameLabel.text = arr[0];
    [_nameImage sd_setImageWithURL:[NSURL URLWithString:arr[1]] placeholderImage:nil];
    // 头像设置圆角
    _nameImage.layer.cornerRadius = 85;
    _nameImage.layer.masksToBounds = YES;
    
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
#pragma mark --- 返回抽屉button
- (IBAction)backButton:(UIButton *)sender {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark --- 分享button
- (IBAction)shareButton:(id)sender {
    
    
    [UMSocialSnsService presentSnsIconSheetView:self
                                         appKey:@"5645e4d367e58e45cb000e7e"
                                      shareText:@""
                                     shareImage:[UIImage imageNamed:@"icon.png"]
                                shareToSnsNames:[NSArray arrayWithObjects:UMShareToSina,UMShareToRenren,UMShareToDouban,nil]
                                       delegate:self];
    
    
}

- (IBAction)exitButton:(UIButton *)sender {
    
    [[UMSocialDataService defaultDataService] requestUnOauthWithType:UMShareToSina  completion:^(UMSocialResponseEntity *response){
        NSLog(@"response is %@",response);
    }];
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setBool:NO forKey:@"isLogin"];
    
    // 发一个通知出去让前面的页面改变头像和昵称
    [[NSNotificationCenter defaultCenter] postNotificationName:@"dataBase" object:nil];
    
    
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}



@end
